#include "InputLayouts.h"

///statics
VertexLayout* InputLayouts::PositionTextureNormalLayout ;
VertexLayout* InputLayouts::PositionTextureLayout ;
VertexLayout* InputLayouts::PositionTextureNormalTangentBinormalLayout;
VertexLayout* InputLayouts::PositionTextureNormalTangentBinormalAnimatedLayout;

void InputLayouts::LoadLayouts(void)
{	
	InputLayouts::PositionTextureNormalLayout = new VertexLayout();
	InputLayouts::PositionTextureNormalLayout->Layout = (D3D11_INPUT_ELEMENT_DESC*) malloc(sizeof(D3D11_INPUT_ELEMENT_DESC) * 3);
	// Define the input layouts (lazy declarations >.< )
	D3D11_INPUT_ELEMENT_DESC ptnl[] = 
	{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};
	memcpy(InputLayouts::PositionTextureNormalLayout->Layout,ptnl,sizeof(ptnl));	
	InputLayouts::PositionTextureNormalLayout->NumElements = ARRAYSIZE(ptnl);
	
	InputLayouts::PositionTextureLayout = new VertexLayout();		
	InputLayouts::PositionTextureLayout->Layout = (D3D11_INPUT_ELEMENT_DESC*) malloc(sizeof(D3D11_INPUT_ELEMENT_DESC) * 2);

	D3D11_INPUT_ELEMENT_DESC ptl[] = 
	{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },		
	};
	memcpy(InputLayouts::PositionTextureLayout->Layout ,ptl,sizeof(ptl));	
	InputLayouts::PositionTextureLayout->NumElements = ARRAYSIZE(ptl);

	InputLayouts::PositionTextureNormalTangentBinormalLayout = new VertexLayout();
	InputLayouts::PositionTextureNormalTangentBinormalLayout->Layout = (D3D11_INPUT_ELEMENT_DESC*) malloc(sizeof(D3D11_INPUT_ELEMENT_DESC) * 5);	
	D3D11_INPUT_ELEMENT_DESC px[] = 
	{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "TANGENT",0, DXGI_FORMAT_R32G32B32_FLOAT,	0,  32,	D3D11_INPUT_PER_VERTEX_DATA, 0 }, 
			{ "BINORMAL",0, DXGI_FORMAT_R32G32B32_FLOAT,0,  44,	D3D11_INPUT_PER_VERTEX_DATA, 0 }, 

	};
	memcpy(InputLayouts::PositionTextureNormalTangentBinormalLayout->Layout,px,sizeof(px));	
	InputLayouts::PositionTextureNormalTangentBinormalLayout->NumElements = ARRAYSIZE(px);


	InputLayouts::PositionTextureNormalTangentBinormalAnimatedLayout = new VertexLayout();
	InputLayouts::PositionTextureNormalTangentBinormalAnimatedLayout->Layout = (D3D11_INPUT_ELEMENT_DESC*) malloc(sizeof(D3D11_INPUT_ELEMENT_DESC) * 7);	
	D3D11_INPUT_ELEMENT_DESC pxa[] = 
	{
			{ "POSITION", 0,DXGI_FORMAT_R32G32B32_FLOAT, 0,  0,		D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "TEXCOORD", 0,DXGI_FORMAT_R32G32_FLOAT,	 0,  12,	D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "NORMAL", 0,  DXGI_FORMAT_R32G32B32_FLOAT, 0,  20,	D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "TANGENT",0,  DXGI_FORMAT_R32G32B32_FLOAT, 0,  32,	D3D11_INPUT_PER_VERTEX_DATA, 0 }, 
			{ "BINORMAL",0, DXGI_FORMAT_R32G32B32_FLOAT, 0,  44,	D3D11_INPUT_PER_VERTEX_DATA, 0 }, 
			{ "BLENDWEIGHTS", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0,  56,	D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "BLENDINDICES", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0,  72,	D3D11_INPUT_PER_VERTEX_DATA, 0 },

	};
	memcpy(InputLayouts::PositionTextureNormalTangentBinormalAnimatedLayout->Layout,pxa,sizeof(pxa));	
	InputLayouts::PositionTextureNormalTangentBinormalAnimatedLayout->NumElements = ARRAYSIZE(pxa);

}

void InputLayouts::Unload(void)
{
	delete PositionTextureLayout->Layout;
	delete PositionTextureLayout;
	delete PositionTextureNormalLayout->Layout;
	delete PositionTextureNormalLayout;
	delete PositionTextureNormalTangentBinormalAnimatedLayout->Layout;
	delete PositionTextureNormalTangentBinormalAnimatedLayout;
}
InputLayouts::InputLayouts(void)
{
}

InputLayouts::~InputLayouts(void)
{	
}

